package com.dkf.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dkf.mapper.SaleplanparaMapper;
import com.dkf.service.SaleplanparaService;
import com.lww.springcloudapi.entity.TabSaleplanpara;
import com.lww.springcloudapi.result.Result;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SaleplanparaServiceImpl extends ServiceImpl<SaleplanparaMapper,TabSaleplanpara> implements SaleplanparaService {
    /**
     * 查询营销活动
     * @param b         判断是否按照有效期查询
     * @param current   起始条数
     * @param size      起始页数
     * @return          统一返回result
     */
    @Override
    public Result findSaleplanparaPage(boolean b, long current, long size) {
        QueryWrapper<TabSaleplanpara> wrapper = new QueryWrapper<>();
        //按有效期查询活动
        if(b){
            wrapper.ge("EXPDATE",new Date());
            wrapper.le("EFFDATE",new Date());
        }
        //分页
        Page<TabSaleplanpara> page=new Page<>(current, size);
        Page<TabSaleplanpara> result=this.page(page);
        return Result.ok(result);
    }

    /**
     * 修改营销活动
     * @param tabSaleplanpara
     * @return  返回修改信息
     */
    @Override
    public Result updataSaleplanpara(TabSaleplanpara tabSaleplanpara) {

        boolean b=this.updateById(tabSaleplanpara);
        if(b){
            return Result.ok();
        }
        return Result.fail();
    }

    /**
     * 添加营销活动
     * @param tabSaleplanpara
     * @return  返回新增信息
     */
    @Override
    public Result addSaleplanpara(TabSaleplanpara tabSaleplanpara) {
        boolean b=this.save(tabSaleplanpara);
        if(b){
            return Result.ok();
        }
        return Result.fail();
    }

    /**
     * 删除营销活动
     * @param id 根据id删除
     * @return 返回删除信息
     */
    @Override
    public Result deleteSaleplanpara(Integer id) {
        boolean b=this.removeById(id);
        if(b){
            return Result.ok();
        }
        return Result.fail();
    }
}
